<?php

    if(!defined('BASEPATH'))
        exit('No direct script access allowed');

    class Home extends CI_Controller
    {

        function __construct()
        {
            parent::__construct();
        }

        public function index()
        {
            $this->home_page();

        }

        public function home_page()
        {
            $this->data['title']="iBookHotel - softver za turitičke agencije";
            $this->template->load('site/home', $this->data);

        }

        public function osistemu()
        {
            $this->data['title']="O iBookHotel sistemu";
            $this->template->load('site/osistemu', $this->data);

        }

        public function karakteristike()
        {
            $this->data['title']="Karakteristike iBookHotel sistema";
            $this->template->load('site/karakteristike', $this->data);

        }

        public function internet_marketing()
        {
            $this->data['title']="Internet marketing";
            $this->template->load('site/internet_marketing', $this->data);

        }

        public function posao()
        {
            $this->data['title']="Informacije za saradnike";
            $this->template->load('site/posao', $this->data);

        }

        public function vijesti()
        {
            require_once("urlify.php");
            $this->load->model('cms_pro', 'cms');
            $this->load->library('translate', array('lang' => 'me'));
            
            $this->data['title']="Najnovije vijesti";

            $news=$this->cms->get_news();
            $this->data['news']=$this->translate->trans_res_array($news);
            $this->template->load('site/vijesti', $this->data);

        }
        
        public function citaj_vijest($vijest){
            
            $news_ID = idFromUrl($vijest,'-');
            
            require_once("urlify.php");
            $this->load->model('cms_pro', 'cms');
            $this->load->library('translate', array('lang' => 'me'));
            $this->data['page'] = $this->translate->trans_row_array( $this->cms->get_post($news_ID) );
            
            $gallery_id = $this->cms->get_gallery_id($news_ID);
            
            if($gallery_id){
                $this->data['gallery'] = $this->cms->get_gallery($gallery_id);
                $this->data['pictures'] = $this->cms->get_pictures($this->data['gallery']['ID']);
                //$this->firephp->log($this->data);
            }
            
            $this->data['title']=$this->data['page']['post_title'];
            $this->data['no_gallery_links'] = TRUE;
            $this->template->load('site/citaj_vijest', $this->data);
        }

        function newsletter()
        {

            $rows=$this->db->get_where('newsletter', array('email' => $this->input->post('email')))->result_array();

            if(count($rows) > 0)
            {
                echo json_encode(array('action' => false, 'msg' => 'Već ste prijavljeni na mejl listu.'));
            }
            else
            {
                $this->db->insert('newsletter', array(
                    'email' => $this->input->post('email'),
                    'created' => time()
                ));

                echo json_encode(array('action' => true, 'msg' => 'Hvala što se se prijavili na mejllistu.'));
            }

        }

    }